#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()//一般最常用重写closeEvent方法
{
    QMessageBox::StandardButton result;
    result = QMessageBox::question(this,
                          "退出程序前的提示",
                          "你做的操作没有保存，现在是否保存",
                          QMessageBox::Yes|QMessageBox::Save|QMessageBox::Cancel|QMessageBox::No,
                          QMessageBox::Save);
    delete ui;
}

void Widget::on_btn_info_clicked()
{
    QString info_tite = "信息消息测试";
    QString info_message = "<b>这是一条提示消息</b><br>";

    QMessageBox::StandardButton standard = QMessageBox::information(this,info_tite,info_message,
                             QMessageBox::Ok | QMessageBox::Cancel | QMessageBox::Save,
                             QMessageBox::Save);

    if(standard == QMessageBox::Ok)
        qDebug() << "提示了info之后，用户选择了OK";

    if(standard == QMessageBox::Cancel)
        qDebug() << "提示了info之后，用户选择了Cancel";

    if(standard == QMessageBox::Save)
        qDebug() << "提示了info之后，用户选择了Save";
}



void Widget::on_btn_about_clicked()
{
    QString info_tite = "关于消息测试";
    QString info_message = "这是一条关于信息提示";

    QMessageBox::about(this,info_tite,info_message);
}


void Widget::on_btn_warning_clicked()
{
    QString info_tite = "关于警告测试";
    QString info_message = "这是一条警告！！！";

    QMessageBox::warning(this,info_tite,info_message,
                         QMessageBox::StandardButtons(QMessageBox::Ok | QMessageBox::Save),
                         QMessageBox::Save);
}


void Widget::on_btn_critical_clicked()
{
    QString info_tite = "紧急信息测试测试";
    QString info_message = "这是一条紧急信息！！！";

    QMessageBox::critical(this,info_tite,info_message);
}


void Widget::on_btn_question_clicked()
{
    QString info_tite = "问题测试";
    QString info_message = "这是一条问题，你是否要保存信息";

    // QMessageBox::StandardButtons standard = QMessageBox::No|QMessageBox::Save;
    QMessageBox::StandardButtons standard(QMessageBox::No|QMessageBox::Save);
    QMessageBox::question(this,info_tite,info_message,standard,QMessageBox::Save);
}

